﻿@model IEnumerable<Layui.Entities.Category>
@{
    ViewData["Title"] = "功能能菜单";
    var canInit = WorkContext.OwnPermission("initCategory");
}

<div class="breadcrumbs" id="breadcrumbs">
    <ul class="breadcrumb">
        <li>
            <i class="ace-icon fa fa-home home-icon"></i>
            <a href="@Url.RouteUrl("mainIndex")">首页</a>
        </li>
        <li class="active">@ViewData["Title"]</li>
    </ul>
</div>
<div class="page-content">
    <div class="page-header">
        <h1>
            @ViewData["Title"]
        </h1>
    </div>
    <div class="row">
        <div class="col-sm-12">
            @if (canInit)
            {
                <a asp-route="initCategory" class="btn btn-sm btn-primary" id="btnInitCategory"><i class="ace-icon fa fa-refresh"></i>初始化</a>
            }
        </div>
    </div>
    <div class="space-2"></div>
    <div class="row">
        <div class="col-sm-12">
            <table id="user_datatable" class="table table-striped table-bordered table-hover dataTable no-footer">
                <tbody>
                    @{
                        var fatherList = Model.Where(o => o.FatherID == null).OrderBy(x=>x.Sort).ToList();
                        foreach (var item in fatherList)
                        {
                            var childList = Model.Where(o => o.FatherID == item.ResouceID).OrderBy(x => x.Sort).ToList();
                            <tr>
                                <td style="width:180px;">
                                    <i class="@item.CssClass"></i>@item.Name 
                                    @if (item.IsMenu)
                                    {
                                        <small class="text-primary">菜单</small>
                                    }
                                </td>
                                @if (childList.Any())
                                {
                                    <td>
                                        <table class="table table-striped table-bordered dataTable no-footer">
                                            <tbody>
                                                @foreach (var child in childList)
                                                {
                                                    var threeList = Model.Where(o => o.FatherID == child.ResouceID).OrderBy(x => x.Sort).ToList();
                                                    <tr>
                                                        <td><i class="@child.CssClass"></i>@child.Name
                                                        @if (child.IsMenu)
                                                        {
                                                            <small class="text-primary">菜单</small>
                                                        }
                                                        </td>
                                                        @if (threeList.Any())
                                                        {
                                                            <td>
                                                                <table class="table table-striped table-bordered dataTable no-footer">
                                                                    <tbody>
                                                                        @foreach (var three in threeList)
                                                                        {
                                                                            <tr>
                                                                                <td>@three.Name</td>
                                                                            </tr>
                                                                        }
                                                                    </tbody>
                                                                </table>
                                                            </td>
                                                        }
                                                        else
                                                        {
                                                            <td></td>
                                                        }
                                                    </tr>
                                                }
                                            </tbody>
                                        </table>
                                    </td>
                                }
                                else
                                {
                                    <td></td>
                                }
                            </tr>
                        }
                    }
                </tbody>
            </table>
        </div>
    </div>

</div>
<script>
    $(function () {
        $('#btnInitCategory').click(function (e) {
            e.preventDefault();
            var url = this.href;
            layer.confirm('您确定要初始化？', function () {
                layer.load();
                $.get(url, function (data) {
                    layer.closeAll();
                    layer.msg(data.Message, { icon: 1 });
                    window.location.reload();
                });
            });
        });

    })
</script>









